﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuantitativeInvestment.Bean;
namespace QuantitativeInvestment.View
{
     partial class StockPoolForm : Form
    {
         public MainForm mainForm;
         public StockPool.StockPool pool;
        public StockPoolForm(MainForm mainForm,StockPool.StockPool pool)
        {
            InitializeComponent();
            this.mainForm = mainForm;
            this.pool=pool;
            generateParameterInputList();
        }
        private void generateParameterInputList()
        {
            this.Text = "股票池-" + this.mainForm.container.name; ;
            int labelPosition = 31;
            int textBoxPositon = 28;
            foreach (Parameter p in this.pool.paraList.Values)
            {

                Label label1 = new System.Windows.Forms.Label();
                // 
                // textBox1
                // 
                if (p.type == "enum")
                {
                    ComboBox comboBox1 = new ComboBox();
                    comboBox1.FormattingEnabled = true;
                    comboBox1.Location = new System.Drawing.Point(100, textBoxPositon);
                    comboBox1.Name = p.name;
                    comboBox1.Size = new System.Drawing.Size(100, 20);
                    comboBox1.TabIndex = 0;
                    foreach (string item in p.enumList)
                    {
                        comboBox1.Items.Add(item);
                    }
                    comboBox1.SelectedText = p.value.ToString();
                    this.Controls.Add(comboBox1);
                }
                else
                {
                    TextBox textBox1 = new System.Windows.Forms.TextBox();
                    textBox1.Location = new System.Drawing.Point(100, textBoxPositon);
                    textBox1.Name = p.name;
                    textBox1.Size = new System.Drawing.Size(100, 21);
                    textBox1.TabIndex = 0;
                    textBox1.Text = p.value.ToString();
                    this.Controls.Add(textBox1);
                }
                // 
                // label1
                // 
                label1.AutoSize = true;
                label1.Location = new System.Drawing.Point(32, labelPosition);
                label1.Name = p.name;
                label1.Size = new System.Drawing.Size(41, 12);
                label1.TabIndex = 1;
                label1.Text = p.name;

                this.Controls.Add(label1);

                textBoxPositon = textBoxPositon + 30;
                labelPosition = labelPosition + 30;

            }
            Button buttonOK = new System.Windows.Forms.Button();
            buttonOK.Location = new System.Drawing.Point(125, textBoxPositon + 30);
            buttonOK.Name = "buttonOK";
            buttonOK.Size = new System.Drawing.Size(75, 23);
            buttonOK.TabIndex = 0;
            buttonOK.Text = "确定";
            buttonOK.UseVisualStyleBackColor = true;
            buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
            this.Controls.Add(buttonOK);
            this.ClientSize = this.ClientSize = new System.Drawing.Size(230, textBoxPositon + 80);

            this.Location = new System.Drawing.Point(100, 100); ;

        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            foreach (Control input in this.Controls)
            {
                if (input.GetType().ToString() == "System.Windows.Forms.TextBox" || input.GetType().ToString() == "System.Windows.Forms.ComboBox")
                {
                    string name = input.Name;
                    string value = input.Text;
                    this.pool.paraList[name].value = value;
                }
            }
            this.mainForm.updateModelView();
            this.Dispose();
        }
    }
}
